//******************************************************************/
//版本说明:
//V0.1		2017-03-30	11:00	yshao	复制自SL909_G01_X32
//V2.1		2019-01-31	11:00	yshao	调整init_end和comm_en,init_mode
//V3.0		2019-05-20	23:00	yshao	复制自LL901_G04_X04_11
//V4.0		2019-08-15	23:00	yshao	修改自LL901_G04_X06_25
//******************************************************************/
//******************************************************************/
//			   全局参数定义
//******************************************************************/
//硬件类型
//`define	YS1028
//`define	H611
//`define	REDUNDANCE

//仿真模式
//`define	SIMULATION	1
//`timescale	1ps/1ps

//FPGA程序模式
`define		APP_MODE	1
//`define	TEST_MODE	2
//`define	BOOT_MODE	3

//******************************************************************/
//			   FPGA顶层
//******************************************************************/
module LL901_G04(
		input	wire			sclkin,
		input	wire			s_pullup,
		
`ifdef H611
		input	wire			key_in,
		
		inout	tri				test_a,
		output	wire			test_b,
		output	wire			test_c,
		output	wire			test_d,
		
		//Flash接口
		output	wire			flash_CS_n,
		output	wire			flash_SCK,
		output	wire			flash_SI,
		input	wire			flash_SO,

		//PHY配置接口
		output	wire			phy_rst,
		output	wire			phy_mdc,
		inout	tri				phy_mdio,
`else
		output	wire			key_in,

		output	wire			JP202_PIN3,
		output	wire			JP202_PIN4,
		output	wire			JP202_PIN5,
		input	wire			JP202_PIN6,
`endif

`ifdef H611
		output	wire			sa_csn,
		output	wire			sa_cke,
		output	wire	[3:0]	sa_dqm,
`else
		output	wire			sa_dqm_l,
		output	wire			sa_dqm_h,
`endif
		output	wire			sa_clk,
		output	wire	[2:0]	sa_cnt,
		output	wire	[10:0]	sa_addr,
		output	wire	[1:0]	sa_bank,
		inout	tri		[31:0]	sa_data,

		input	wire			mcu_dmx_tx,		//uart2_sync,
		output	reg				mcu_dmx_rx,		//uart3_sync,

		input	wire			mcu_fpga_ctrl,		//mcu到fpga的模式控制信号

		input	wire			mcu_spi_fpga,		//spi工作在通讯模式
		input	wire			mcu_spi_clk,
		input	wire			mcu_spi_mosi,
		output	wire			mcu_spi_miso,

		output	wire			spi2_cs,
		output	wire			spi2_clk,
		output	wire			spi2_mosi,

`ifdef H611
		output	wire			sd_clk,
		output	tri				sd_cmd_sdi,
		output	wire			sd_dat0_sdo,
		output	wire			sd_dat1,
		output	wire			sd_dat2,
		output	wire			sd_dat3_cs,
		output	wire			sd_cd,
		output	wire			sd_wp,
`else
		output	wire			sd_clk,
		inout	tri				sd_cmd_sdi,
		input	wire			sd_dat0_sdo,
		input	wire			sd_dat1,
		input	wire			sd_dat2,
		inout	wire			sd_dat3_cs,
		input	wire			sd_cd,
		input	wire			sd_wp,
`endif

		input	wire			gp0_rxc,
		input	wire			gp0_rxdv,
		input	wire	[3:0]	gp0_rxd,
		output	wire			gp0_txc,
		output	wire			gp0_txen,
		output	wire	[3:0]	gp0_txd,
		
		input	wire			gp1_rxc,
		input	wire			gp1_rxdv,
		input	wire	[3:0]	gp1_rxd,
		output	wire			gp1_txc,
		output	wire			gp1_txen,
		output	wire	[3:0]	gp1_txd,

		output	wire	[7:0]	port_da,
		output	wire	[7:0]	port_le,
`ifdef H611
		output	wire	[5:0]	port_ex,
		input	wire			port_in,
`else
		inout	tri		[7:0]	port_ex,
		input	wire	[7:0]	port_in,
`endif
		
		output	wire			led_g
		);

//****************************************************************
//		内部信号
//****************************************************************
//复位&时钟
wire			resetb, oclk, sclk, clk_25M;
wire	[20:0]	time_us, sync_us;
wire	[1:0]	pll_lock, pll_reset;

//PHY接口
wire			sub_mode;
wire	[1:0]	depth_state;
wire	[9:0]   current_depth;
wire	[5:0]	device_port;
`ifdef H611
wire	[1:0]	device_main;
`endif

wire			rec_flag_a, rec_flag, rec_error;
wire	[7:0]	rec_data;
wire	[1:0]	force_send;
wire			send_flag, pre_flag;
wire	[7:0]	send_data;
wire	[1:0]	rec_vendor;
wire			yt_vs_pre, redu_flag, blank_flag, input_L9;
wire	[7:0]	phy_state;

//PHY设置总线相关信号
wire			init_mode, set_d_ok, ext_d_ok;
wire	[31:0]	set_addr;
wire	[7:0]	set_data, rd_data;
wire	[7:0]	mcu_rd_hub;

//MCU设置总线相关信号
wire			mcu_set_d_ok, mcu_ext_d_ok;
wire	[31:0]	mcu_set_addr;
wire	[7:0]	mcu_set_data, mcu_rd_data;

//显示数据相关
wire			vs_L9, ds_L9, h_start_L9, l2048_mode;
wire			ds_a, h_start_a, vs_sd, ds_sd, h_start_sd;
wire	[7:0]	data_L9, data_a, data_sd;
wire	[10:0]	h_num_L9, h_num_a, h_num_sd, h_offset;

wire	[15:0]	state;
wire	[1:0]	color_restore_type;
wire	[7:0]	testmode;
wire	[8:0]	cascade_light;

reg				vs, ds, h_start;
reg		[7:0]	data;
reg		[10:0]	h_num;

//输出模块接口信号
wire			vs_out, out_sync;
wire			mem_read_req, mem_data_sync;
wire	[9:0]	mem_pixel_addr;
wire	[31:0]	mem_read_data;	
wire	[7:0]	port_da_o, port_le_o;

//DMX输出信号
wire			dmx_send_flag, mcu_dmx_ten;

//SD播放信号
wire	[7:0]	sd_state;
wire			input_local, force_dis_en, force_send_play;
reg				local_dis_flag;

//SDRAM控制信号
wire	[1:0]	frame_buf_sel;
wire			map_adj_en;

//反馈网口信号
wire			send_flag_sd, pre_flag_sd;
wire	[7:0]	send_data_sd;

//RDM反馈滤波
reg		[2:0]	div_count;
reg				clk_16M;
reg		[20:0]	dmx_t;
reg		[2:0]	dmx_sum_a, dmx_sum_b, dmx_sum_c, dmx_sum_d;
reg		[4:0]	dmx_sum;
wire			mcu_dmx_rx_a;

//**********调试用信号**********
wire	[15:0]	debug_data, phy_tout;
wire	[31:0]	a1_tout, sa_tout, sd_tout;
wire	[15:0]	out_tout, ms_tout;

//******************************************************************/
//			   参数定义
//******************************************************************/
//程序版本信息
parameter	MAIN_FUNCTION	=  "L";		//ASCII "S"  
parameter	SUB_FUNCTION	=  "L";		//ASCII "L"  
parameter	MAIN_SOLUTION	=  9;		//"9"        
parameter	SUB_SOLUTION	=  1;		//"09"       
parameter	APPLICATION_TYPE=  "T";		//ASCII "G"  
parameter	MAIN_VERSION	=  8'd4;	//"03"       
parameter	SUB_VERSION		=  8'd6;	//"X01"
parameter	MINI_VERSION	=  8'd81;	//" "  

//模块参数设置
defparam	main_ctrl.phy_comm.state_ctrl.main_function	=MAIN_FUNCTION;
defparam	main_ctrl.phy_comm.state_ctrl.sub_function	=SUB_FUNCTION;
defparam	main_ctrl.phy_comm.state_ctrl.main_solution	=MAIN_SOLUTION;
defparam	main_ctrl.phy_comm.state_ctrl.sub_solution	=SUB_SOLUTION;
defparam	main_ctrl.phy_comm.state_ctrl.application_type	=APPLICATION_TYPE;
defparam	main_ctrl.phy_comm.state_ctrl.main_version	=MAIN_VERSION;
defparam	main_ctrl.phy_comm.state_ctrl.sub_version	=SUB_VERSION;
defparam	main_ctrl.phy_comm.state_ctrl.mini_version	=MINI_VERSION;

defparam	main_ctrl.mcu_comm.main_function	=	MAIN_FUNCTION;
defparam	main_ctrl.mcu_comm.sub_function		=	SUB_FUNCTION;
defparam	main_ctrl.mcu_comm.main_solution	=	MAIN_SOLUTION;
defparam	main_ctrl.mcu_comm.sub_solution		=	SUB_SOLUTION;
defparam	main_ctrl.mcu_comm.application_type	=	APPLICATION_TYPE;
defparam	main_ctrl.mcu_comm.main_version		=	MAIN_VERSION;
defparam	main_ctrl.mcu_comm.sub_version		=	SUB_VERSION;
defparam	main_ctrl.mcu_comm.mini_version		=	MINI_VERSION;

//**************************************************************
//			时钟和复位
//**************************************************************
sys_reset_clk sys_reset_clk(
		//输入时钟
		.sclkin(sclkin),

		//输出复位和时钟
		.resetb(resetb),
		.sclk(sclk),
		.oclk(oclk),
		.sa_clk(sa_clk),
		.clk_25M(clk_25M),

		//分频时钟
		.time_us(time_us),
		.sync_us(sync_us),

		//按键检测
		.pll_reset(2'b00),
		.pll_lock(),

		//调试信号	
		.tout()
		);

assign	pll_reset = 2'b00;

//**************************************************************
//			通讯模块
//**************************************************************
phy_interface phy_interface(
		.resetb(resetb),
		.sclk(sclk),
                
		.sync_16ms(sync_us[14]),

		//其他外部相关信号
		.sub_mode(sub_mode),
		.cas_depth_adj(depth_state[1]),
		.local_depth(current_depth[7:0]),

		.tx_err_en(1'b0),

		//PORTA接口
		.gp0_rxc(gp0_rxc),
		.gp0_rxdv(gp0_rxdv),
		.gp0_rxd(gp0_rxd),
		.gp0_txc(gp0_txc),
		.gp0_txen(gp0_txen),
		.gp0_txd(gp0_txd),
		
		//PORTB接口
		.gp1_rxc(gp1_rxc),
		.gp1_rxdv(gp1_rxdv),
		.gp1_rxd(gp1_rxd),
		.gp1_txc(gp1_txc),
		.gp1_txen(gp1_txen),
		.gp1_txd(gp1_txd),
		
		//内部的接收接口
		.rec_flag_a(rec_flag_a),
		.rec_flag(rec_flag),
		.rec_data(rec_data),
		.rec_error(rec_error),
		.rec_error_sync(),
		
		//内部的发送接口
		.force_send(force_send),
		.send_flag(send_flag),
		.pre_flag(pre_flag),
		.send_data(send_data),

		//给内部的其他信号
		.input_port(input_port),
		.rec_vendor(rec_vendor),
		.yt_vs_pre(yt_vs_pre),
		.input_active(input_L9),
		.redu_flag(redu_flag),
		.blank_flag(blank_flag),
		.phy_state(phy_state),
		
		.tout(phy_tout)
		);
		
//**************************************************************
//			FPGA主控逻辑
//**************************************************************
main_ctrl main_ctrl(
		//复位时钟，按键，Led
		.resetb(resetb),
		.sclk(sclk),

		.time_us(time_us),
		.sync_us(sync_us),
		
		//按键和指示灯
		.key_in(1'b0),
		.led_g(led_g),

`ifdef H611
		//Flash接口
		.flash_CS_n(flash_CS_n),
		.flash_SCK(flash_SCK),
		.flash_SI(flash_SI),
		.flash_SO(flash_SO),

		//PHY配置接口
		.phy_rst(phy_rst),
		.phy_mdc(phy_mdc),
		.phy_mdio(phy_mdio),

		//冗余控制信号
		.device_main(device_main),
`endif

		//外部MCU通讯接口
		.mcu_fpga_ctrl(mcu_fpga_ctrl),
		
		.mcu_spi_fpga(mcu_spi_fpga),
		.mcu_spi_clk(mcu_spi_clk),
		.mcu_spi_mosi(mcu_spi_mosi),
		.mcu_spi_miso(mcu_spi_miso),

		.spi2_cs(spi2_cs),
		.spi2_clk(spi2_clk),
		.spi2_mosi(spi2_mosi),

		//PHY通讯接口
		.sub_mode(sub_mode),
		.depth_state(depth_state),
		.current_depth(current_depth),


		.input_L9(input_L9),
		.phy_state(phy_state),
		.redu_flag(redu_flag),
		.blank_flag(blank_flag),
		.rec_vendor(rec_vendor),
		
		.rec_flag_a(rec_flag_a),
		.rec_flag(rec_flag),
		.rec_data(rec_data),
		.rec_error(rec_error),
		.rec_error_sync(),
		
		.force_send(force_send),
		.send_flag(send_flag),
		.pre_flag(pre_flag),
		.send_data(send_data),
		
		//PHY总线接口
		.init_mode(init_mode),
		.set_d_ok(set_d_ok),
		.ext_d_ok(ext_d_ok),
		.set_addr(set_addr),
		.set_data(set_data),
		.rd_data(rd_data),
		.debug_data(debug_data),

		//MCU总线接口
		.mcu_set_d_ok(mcu_set_d_ok),
		.mcu_ext_d_ok(mcu_ext_d_ok),
		.mcu_set_addr(mcu_set_addr),
		.mcu_set_data(mcu_set_data),
		.mcu_rd_data(mcu_rd_hub),

		//L9显示数据接口
		.vs_L9(vs_L9),
		.ds_L9(ds_L9),
		.data_L9(data_L9),
		.h_start_L9(h_start_L9),
		.h_num_L9(h_num_L9),
		.l2048_mode(l2048_mode),

		.h_offset(h_offset),
		.state(state),
		.color_restore_type(color_restore_type),
		.testmode(testmode),
		.cascade_light(cascade_light),

		//Artnet显示数据接口
		.input_artnet(input_artnet),
		.ds_a(ds_a),
		.data_a(data_a),
		.h_start_a(h_start_a),
		.h_num_a(h_num_a),

		//背板控制接口
		.device_port(device_port),
		.fpga_dmx_send(dmx_send_flag),
		.mcu_dmx_ten(mcu_dmx_ten),
		
		//SD卡MCU控制接口
		.mcu_sd_en(mcu_sd_en),
		.mcu_sd_miso(mcu_sd_miso),
		
		//SD发送数据包接口
		.force_send_play(force_send_play),
		.send_flag_dis(send_flag_sd),
		.pre_flag_dis(pre_flag_sd),
		.send_data_dis(send_data_sd),

		//SD卡状态
		.sd_state(sd_state),
		
		//调试接口
		.tout()   
		);

//**************************************************************
//         		SD卡控制接口
//************************************************************** 
`ifdef H611
assign	sd_state = 0;
//assign	sd_clk = 0;
assign	mcu_sd_miso = 0;
assign	input_local = 0;
assign	force_dis_en = 0;
assign	force_send_play = 0;
assign	vs_sd = 0;
assign	ds_sd = 0;
assign	data_sd = 0;
assign	h_start_sd = 0;
assign	h_num_sd = 0;
assign	send_flag_sd = 0;
assign	pre_flag_sd = 0;
assign	send_data_sd = 0;
`else
sdcard_top sdcard_top(
		//复位&时钟
		.resetb			(resetb),
		.sclk			(sclk),
		.clk_25M		(clk_25M),

		.time_us		(time_us),
		.sync_us		(sync_us),

		//SD卡状态
		.sd_state		(sd_state),

		//SD卡通讯接口
		.sd_clk			(sd_clk),
		.sd_cmd_sdi		(sd_cmd_sdi),
		.sd_dat0_sdo	(sd_dat0_sdo),
		.sd_dat1		(sd_dat1),
		.sd_dat2		(sd_dat2),
		.sd_dat3_cs		(sd_dat3_cs),
		.sd_cd			(sd_cd),
		.sd_wp			(sd_wp),

		//MCU控制接口
		.mcu_sd_en		(mcu_sd_en),
		.mcu_fpga_ctrl	(mcu_fpga_ctrl),
		.mcu_spi_clk	(mcu_spi_clk),
		.mcu_spi_mosi	(mcu_spi_mosi),
		.mcu_sd_miso	(mcu_sd_miso),

		//MCU设置接口
		.cmd_d_ok		(mcu_ext_d_ok),
		.cmd_addr		(mcu_set_addr),
		.cmd_data		(mcu_set_data),

		//sd播放使能
		.input_local	(input_local),
		.force_dis_en	(force_dis_en),
		.force_send_play(force_send_play),
		
		//本地截取范围
		.h_offset		(h_offset),

		//SD显示信号
		.vs_sd			(vs_sd),
		.ds_sd			(ds_sd),
		.data_sd		(data_sd),
		.h_start_sd		(h_start_sd),
		.h_num_sd		(h_num_sd),
		
		//网口发送信号
		.send_flag_sd	(send_flag_sd),
		.pre_flag_sd	(pre_flag_sd),
		.send_data_sd	(send_data_sd),
		
		//调试信号
		.tout			(sd_tout)
		);
`endif

//SD卡显示使能判断
always @(posedge sclk)
	if (force_dis_en == 1)
		local_dis_flag <= 1;
	else if ((input_L9 == 1) || (input_artnet == 1))
		local_dis_flag <= 0;
	else if (input_local == 1)
		local_dis_flag <= 1;
	else
		local_dis_flag <= 0;

//**************************************************************
//         		显示数据选通
//************************************************************** 
//显示数据选通，MCU有优先控制权
always @(posedge sclk)
	if (init_mode == 1)begin
		vs <= 1'b0;
		ds <= 1'b0;
		data <= 8'h0;
		h_start <= 1'b0;
		h_num <= 11'h0;
		end
	else if (local_dis_flag == 1)begin
		vs <= vs_sd;
		ds <= ds_sd;
		h_num <= h_num_sd;
		data <= data_sd;
		h_start <= h_start_sd;
		end
	else if (input_artnet == 1) begin
		vs <= 1'b0;
		ds <= ds_a;
		h_num <= h_num_a;
		data <= data_a;
		h_start <= h_start_a;
		end
	else if (input_L9 == 1) begin
		vs <= vs_L9;
		ds <= ds_L9;
		h_num <= h_num_L9;
		data <= data_L9;
		h_start <= h_start_L9;
		end
	else begin
		vs <= 1'b0;
		ds <= 1'b0;
		data <= 8'h0;
		h_start <= 1'b0;
		h_num <= 11'h0;
		end

//**************************************************************
//         		SDRAM控制接口
//************************************************************** 
L9_sdram_top_01 sdram_top(
		//复位和时钟
		.resetb(resetb),
		.sclk(sclk),
		.sync_16us(sync_us[4]),
		
		.ext_d_ok(ext_d_ok),
		.set_addr(set_addr),
		.set_data(set_data),

		//写显示数据接口
		.dsin(ds),
		.din(data),
		.h_start(h_start),
		.h_num(h_num),
		.l2048_mode(l2048_mode),
		.input_artnet(input_artnet),
		.device_port(device_port),
        
		//显示数据读接口
		.frame_buf_sel		(frame_buf_sel), 
		.mem_read_req		(mem_read_req),
		.mem_pixel_addr		(mem_pixel_addr), 
                .mem_data_sync		(mem_data_sync),
		.mem_read_data		(mem_read_data),
		.map_adj_en		(map_adj_en),
		
		//sdram接口
	        .sa_clk(),
	        .sa_cnt(sa_cnt),
	        .sa_addr(sa_addr),
	        .sa_bank(sa_bank),
	        .sa_data(sa_data),
	        
		//调试输出
	        .tout(sa_tout)
        	);

`ifdef H611
assign	sa_csn = 1'b0;
assign	sa_cke = 1'b1;
assign	sa_dqm = 4'b0000;
`else
assign sa_dqm_l = 1'b0;
assign sa_dqm_h = 1'b0;
`endif

//**************************************************************
//		        显示控制模块
//************************************************************** 
display_top display_top(
		//复位&时钟
		.resetb			(resetb),
		.sclk			(sclk),
		.oclk			(oclk),

		.time_us		(time_us),
		.sync_us		(sync_us),

		//PHY设置总线
		.set_d_ok		(set_d_ok),
		.set_addr		(set_addr),
		.set_data		(set_data),
		.rd_data		(rd_data),

		//MCU设置接口
		.cmd_d_ok		(mcu_ext_d_ok),
		.cmd_addr		(mcu_set_addr),
		.cmd_data		(mcu_set_data),
		.cmd_rd_d		(mcu_rd_hub),

		//MCU辅助通讯
		.mcu_dmx_ten		(mcu_dmx_ten),
		.mcu_dmx_tx		(mcu_dmx_tx),
		.mcu_dmx_rx		(mcu_dmx_rx_a),

		//控制信号
		.init_mode		(init_mode),
		.local_dis_flag		(local_dis_flag),
		.input_artnet		(input_artnet),
		.input_L9		(input_L9),
		.vs			(vs),

		.device_port		(device_port),
		.dmx_send_flag		(dmx_send_flag),
		
		//显示设置包信号
		.state			(state[7:0]),
		.state_2		(state[15:8]),
		.cascade_light		(cascade_light),
		.testmode		(testmode),

		//显示数据读接口
		.frame_buf_sel		(frame_buf_sel), 
		.mem_read_req		(mem_read_req),
		.mem_pixel_addr		(mem_pixel_addr), 
                .mem_data_sync		(mem_data_sync),
		.mem_read_data		(mem_read_data),
		.map_adj_en		(map_adj_en),
		
		//帧输出起始
		.vs_out			(vs_out),
		.out_sync		(out_sync),
		
		//端口输入输出
		.port_da		(port_da_o),
		.port_le		(port_le_o),
		.port_ex		(port_ex),
`ifdef H611
		.port_in		(port_in),
`endif
		
		//调试信号
		.tout			(out_tout)
		);

`ifdef REDUNDANCE
//**************************************************************
//		        冗余控制模块
//************************************************************** 
//冗余判断
out_judge out_judge(
		.resetb			(resetb),
		.sclk			(sclk),
		.sync_1us		(sync_us[0]),
		.sync_1ms		(sync_us[10]),
		
		.out_en			(out_en),
		
		.device_main		(device_main),
		.input_ok		(input_L9),
		.vs_out			(vs_out),
		
		.test_a			(test_a),
		
		.tout			(ms_tout)
		);
		
assign	port_da = (out_en == 1)? port_da_o : 8'hzz;
assign	port_le = (out_en == 1)? port_le_o : 8'hzz;
`elsif H611
assign	port_da = port_da_o;
assign	port_le = port_le_o;
`else
assign  port_da = (debug_output == 0)? port_da_o : {port_da_o[7:1], sd_tout[5]};
assign  port_le = (debug_output == 0)? port_le_o : sd_tout[15:8];
`endif
		
//**************************************************************
//		        RDM信号滤波
//**************************************************************
always	@(posedge sclk)
	div_count <= div_count + 1;

always	@(posedge sclk)
	clk_16M <= div_count[2];

always	@(posedge clk_16M)
	dmx_t <= {dmx_t[19:0], mcu_dmx_rx_a};

always	@(posedge clk_16M) begin
	dmx_sum_a <= dmx_t[1] + dmx_t[2] + dmx_t[3] + dmx_t[4] + dmx_t[5];
	dmx_sum_b <= dmx_t[6] + dmx_t[7] + dmx_t[8] + dmx_t[9] + dmx_t[10];
	dmx_sum_c <= dmx_t[11] + dmx_t[12] + dmx_t[13] + dmx_t[14] + dmx_t[15];
	dmx_sum_d <= dmx_t[16] + dmx_t[17] + dmx_t[18] + dmx_t[19] + dmx_t[20];
	dmx_sum <= dmx_sum_a + dmx_sum_b + dmx_sum_c + dmx_sum_d;
	end

always	@(posedge clk_16M or negedge resetb)
	if (resetb == 0)
		mcu_dmx_rx <= 1;
	else if (dmx_sum <= 6)
		mcu_dmx_rx <= 0;
	else if (dmx_sum >= 14)
		mcu_dmx_rx <= 1;
 
//************************************************************/
//		调试接口
//************************************************************/                    
assign	debug_data = sd_tout[31:16];

reg		debug_output;

always	@(posedge sclk or negedge resetb)
	if(resetb==0)
		debug_output <= 0;
	else if ((mcu_ext_d_ok == 1) && (mcu_set_addr == 32'h0001_2116)) begin
		if (mcu_set_data == 8'h3C)
			debug_output <= 1;
		else
			debug_output <= 0;
		end

//assign  port_le = a1_tout[15:8];
//assign  port_da = a1_tout;
//assign  port_le = {mcu_spi_fpga, mcu_spi_clk, mcu_spi_mosi, mcu_spi_miso, mcu_fpga_ctrl, mcu_sd_en, mcu_sd_rd};  
//assign  port_da = spi_tout;
//assign	port_le = sd_tout[7:0];

`ifdef H611
assign	sd_dat1 = out_tout[0];
assign	sd_wp = ms_tout[0];
assign	sd_clk = ms_tout[1];
assign	sd_cmd_sdi = ms_tout[2];
assign	sd_dat2 = ms_tout[3];
assign	sd_dat0_sdo = ms_tout[4];
assign	sd_cd = ms_tout[5];
assign	sd_dat3_cs = ms_tout[6];
assign	tout[0] = port_a[0];
assign	tout[1] = port_a[1];
`else
//assign	key_in = mcu_spi_fpga;
//assign	JP202_PIN3 = spi2_cs;
//assign	JP202_PIN4 = spi2_clk;
//assign	JP202_PIN5 = spi2_mosi;

//assign	JP202_PIN3 = port_le[0];//sd_tout[0];//sa_tout[0];//vs;//spi2_cs;
//assign	JP202_PIN4 = port_le_o[0];//input_L9;//ds;//spi2_clk;
//assign	JP202_PIN5 = out_tout[1];//local_dis_flag;//input_artnet;//spi2_mosi;

//assign	key_in = (debug_output == 0)? mcu_spi_fpga : sd_tout[4];
//assign	JP202_PIN3 = (debug_output == 0)? spi2_cs : sd_tout[1];
//assign	JP202_PIN4 = (debug_output == 0)? spi2_clk : sd_tout[2];
//assign	JP202_PIN5 = (debug_output == 0)? spi2_mosi : sd_tout[3];
assign	key_in = out_sync;
assign	JP202_PIN3 = out_tout[0];
assign	JP202_PIN4 = sd_tout[1];
assign	JP202_PIN5 = sd_tout[1];
`endif

endmodule